<?php
header('Content-Type: text/html; charset=UTF-8');

require 'database.php';
$db = new DB();

$url = isset($_GET['url']) ? strval($_GET['url']) : NULL;
$tag = isset($_GET['tag']) ? strval($_GET['tag']) : NULL;

$url = str_replace('%27', "'", $url);

$Qry = 'SELECT g_id, tags
		FROM games
		WHERE tags LIKE "%' .  $url . '%"';
// echo $Qry;
if ($db->numRows($Qry) > 0) {
	$res = $db->fetchAll($Qry);

	foreach ($res as $key=>$value) {
		$str = str_replace($url, $tag, $value['tags']);

		// Change new category for all games same category
		$query = 'UPDATE games SET tags = "' . $str . '" WHERE g_id = ' . $value['g_id'];

		echo $query . '<br />';

		$db->Query($query);
	}
}